#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#define IPC_PATH "./.fifo"

using namespace std;
int main()
{
    int pipefd = open(IPC_PATH, O_WRONLY);
    if (pipefd < 0)
    {
        cerr << "open error" << endl;
        return 1;
    }
    char inbuff[1024];
    while (1)
    {
        printf("请输入需要发送的消息：");
        fflush(stdout);
        memset(inbuff, 0, sizeof(inbuff));
        if (fgets(inbuff, sizeof(inbuff), stdin) != nullptr)
        {
            inbuff[strlen(inbuff) - 1] = '\0'; //去掉回车
            write(pipefd, inbuff, strlen(inbuff));
        }
        else
        {
            break;
        }
    }
    close(pipefd);
    cout << "client exit" << endl;
    return 0;
}